using VMukti.DataAccess.VMuktiGrid;
using System.Data.SqlClient;
using System.Collections.Generic;
using VMukti.Business.CommonDataContracts;
using System;
using VMuktiAPI;
//using VMukti.Business.CommonDataContracts;


namespace VMukti.Business.VMuktiGrid
{
    public class ClsPageCollection : ClsBaseCollection<ClsPage>
    {
        public static ClsPageCollection GetAll()
        {
            try
            {
                ClsPageCollection obj = new ClsPageCollection();
                if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp)
                {
                    //ExecuteDataSet("select pagetitle,id from page where isdeleted='false'", CommandType.Text, null);
                    obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("select pagetitle,id from page where isdeleted='false'").dsInfo);
                }
                else
                {
                    obj.MapObjects(new ClsPageDataService().GetPages());
                }
                return obj;
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--VmuktiBussiness--:--VmuktiGrid--:--Pages--:--ClsPageCollection.cs--:--GetAll()--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
                return null;
            }
        }

        public static ClsPageCollection GetUPageAllocated(int intUserId)
        {
            try
            {
                ClsPageCollection obj = new ClsPageCollection();
                if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp)
                {
                    //ExecuteDataSet("spGetUsersPageAllocated", CommandType.StoredProcedure,
                    //CreateParameter("@pUserID", SqlDbType.BigInt, intUserId));

                    List<clsSqlParametersInfo> lstSP = new List<clsSqlParametersInfo>();

                    clsSqlParametersInfo objInfo = new clsSqlParametersInfo();
                    objInfo.Direction = "Input";
                    objInfo.PName = "@pUserID";
                    objInfo.PValue = intUserId;
                    objInfo.PDBType = "BigInt";
                    objInfo.PSize = 200;

                    lstSP.Add(objInfo);

                    clsSqlParameterContract CSqlInfo = new clsSqlParameterContract();
                    CSqlInfo.objParam = lstSP;

                    obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("spGetUsersPageAllocated", CSqlInfo).dsInfo);
                }
                else
                {
                    obj.MapObjects(new ClsPageDataService().GetPageAllocated(intUserId));
                }
                return obj;
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--VmuktiBussiness--:--VmuktiGrid--:--Pages--:--ClsPageCollection.cs--:--GetUPageAllocated()--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
                return null;
            }
        }
    }
}
